<template>
   <h2>房价价格录入</h2>
   <table>
    <tr>
        <td>具体房价</td>
        <td>
            <input type="text" placeholder="请输入具体房价" v-model="Rinfo.MyProPerty">
        </td>
    </tr>
    <tr>
        <td>房型</td>
        <td>
            <select v-model="Rinfo.Rid">
                <option value="0">请选择</option>
                <option v-for="item in info" :value="item.RId">{{item.RName}}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>收款方式</td>
        <td>
            <input type="radio" :value="true" v-model="Rinfo.GetMoneyType">预定收费
            <input type="radio" :value="false" v-model="Rinfo.GetMoneyType">到店付费
        </td>
    </tr>
    <tr>
        <td>房间数量</td>
        <td>
            <input type="text" placeholder="请输入房间数量" v-model="Rinfo.FNum">
        </td>
    </tr>
    <tr>
        <td>早餐数量</td>
        <td>
            <input type="text" placeholder="请输入早餐数量" v-model="Rinfo.BreakFirst">
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="添加" @click="add">
        </td>
    </tr>
   </table>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'

const info=ref([{
    RId:0,
    RName:''
}])


const Rinfo=ref({
    MyProPerty:'',
    GetMoneyType:'',
    FNum:'',
    BreakFirst:'',
    Rid:''
})


//创建生命周期函数钩
onMounted(()=>{
    LoadData()
})
const LoadData=()=>{
    axios.get('https://localhost:7231/api/Room/ShowRoomType')
    .then(res=>{
        info.value=res.data
    })
    .catch(err=>{
        console.log(err)
    })
}

const add=()=>{
    axios.post('https://localhost:7231/api/Room/AddRoomPrice',{
        MyProPerty:Rinfo.value.MyProPerty,
        GetMoneyType:Rinfo.value.GetMoneyType,
        FNum:Rinfo.value.FNum,
        BreakFirst:Rinfo.value.BreakFirst,
        Rid:Rinfo.value.Rid
    })
    .then(res=>{
        if(res.data>0){
            alert('添加成')
        }else{
            alert('添加失败')
        }
    })
    .catch(err=>{
        console.log(err)
    })
}

</script>

<style scoped>

</style>